package com.fenqiyong.www.action;

import android.content.Context;

import com.tougc.bean.beans.BEvent;
import com.tougc.bean.beans.Successful14K;

import javax.inject.Inject;

import io.reactivex.Observable;
import ren.nearby.http.request.BaseObserver;
import ren.nearby.http.request.HttpApi;
import ren.nearby.http.request.RxResultHelper;
import ren.nearby.http.request.SchedulersCompat;
import ren.nearby.http.utils.util.RxDisposble;

/**
 * Created by Administrator on 2018/5/18 0018.
 */

public class SplashActPresent implements SplashActContract.Action {
    SplashActContract.View mView;  // 需要抽象出来
    @Inject
    HttpApi mApi;
    @Inject
    Context context;

    @Inject
    SplashActPresent() {
    }

    @Override
    public void takeView(SplashActContract.View view) {
        mView = view;
    }

    @Override
    public void dropView() {
        mView = null;
        RxDisposble.getInstance().unSubscribe();
    }


    @Override
    public void channel(String channel) {
        Observable ob = mApi.channel("doudouhua");
        BaseObserver observer = new BaseObserver<Successful14K>(mView.getActivity()) {


            @Override
            public void onNext(Successful14K k14) {
                mView.AorB(k14.getMode_switch());

            }
        };
        ob.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
                .compose(RxResultHelper.handleResult14K())
                .subscribe(observer);
    }

    @Override
    public void smsSend() {

    }

    @Override
    public void event() {
        Observable ob = mApi.event("doudouhua");
        BaseObserver observer = new BaseObserver<BEvent>(mView.getActivity()) {


            @Override
            public void onNext(BEvent k14) {
                mView.BUi(k14.getActivity_info().getImage());

            }
        };
        ob.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
                .compose(RxResultHelper.handleResult14K())
                .subscribe(observer);
    }
}


